//
//  HeTongVC.m
//  tristana
//
//  Created by neobug on 2021/1/6.
//  Copyright © 2021 李康. All rights reserved.
//

#import "HeTongVC.h"

#import <Masonry/Masonry.h>
#import "HeTongCollectionViewCell.h"
#import "HeTongDetailVC.h"

@interface HeTongVC () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (strong, nonatomic) UICollectionView *collevtionView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation HeTongVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initAllPropertys];
    [self setupUI];
    [self loadData];
}


#pragma mark - Public Method

#pragma mark - Life Cycle

#pragma mark - Data Query
- (void)loadData {
    self.dataSource = [@[@{@"type":@0, @"title":@"标准借条格式范本"}, @{@"type":@1, @"title":@"车辆抵押借条范本"}, @{@"type":@2, @"title":@"个人借条合同范本"}, @{@"type":@3, @"title":@"公司借条格式范本"}, @{@"type":@4, @"title":@"借东西借条范文范本"}] mutableCopy];
    [self.collevtionView reloadData];
}
#pragma mark - Notification

#pragma mark - UI
- (void)initAllPropertys {
    self.title = @"合同模版";
}

- (void)setupUI {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    self.collevtionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    layout.minimumLineSpacing = 20;
    layout.minimumInteritemSpacing = 20;
    [self.view addSubview:self.collevtionView];
    self.collevtionView.delegate = self;
    self.collevtionView.dataSource = self;
    self.collevtionView.backgroundColor = [UIColor whiteColor];
    [self.collevtionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.collevtionView registerNib:[UINib nibWithNibName:@"HeTongCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HeTongCollectionViewCell"];
    [self.collevtionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}
#pragma mark - Delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HeTongCollectionViewCell *cell = (HeTongCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"HeTongCollectionViewCell" forIndexPath:indexPath];
    cell.dic = self.dataSource[indexPath.item];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = self.dataSource[indexPath.item];
    HeTongDetailVC *vc = [[HeTongDetailVC alloc] init];
    vc.dic = dic;
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(([UIScreen mainScreen].bounds.size.width-20)/2, 130);
}
 
#pragma mark - Private Method

#pragma mark - Overwrite Method

#pragma mark - Event Response

#pragma mark - Setter

#pragma mark - Getter
- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

@end
